<?xml version="1.0" encoding="UTF-8" ?>
<!---
    -
    -@Author ${author}
    -@Email ${email}
    -@Date ${date?string("yyyy-MM-dd HH:mm:ss")}
    -
    -->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<#assign classFullName = packageName+"."+className> <#-- 创建变量 x -->

<mapper namespace="${mapperPackageName}.${className}Mapper" >
    <sql id="${className}_columnList">
    <#list attrs as attr>${attr.columnName}<#if attr_index < attrs?size -1 >,</#if></#list>
    </sql>
    <sql id="${className}_selectall">
        select <include refid="${className}_columnList"/> from ${tableName}
    </sql>
    <!--int insert(${className} ${className?uncap_first});-->
    <insert id="insert" parameterType="${classFullName}" >
        INSERT INTO ${tableName}(
            <include refid="${className}_columnList"/>
        ) VALUES (
        <#list attrs as attr>
            ${"#{"+attr.name+"}"}<#if attr_index < attrs?size -1 >,</#if>
        </#list>
        )
    </insert>

    <!--int deleteByPrimaryKey(Long id);-->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
        delete from ${tableName} where id = ${r'#{id}'}
    </delete>

    <!--int updateByPrimaryKey(${className} ${className?uncap_first});-->
    <update id="updateByPrimaryKey" parameterType="${classFullName}" >
        update ${tableName}
        set
        <#list attrs as attr>
            <#if attr.name!='id' >
            ${attr.columnName} =${"#{"+attr.name+"}"}<#if attr_index < attrs?size -1 >,</#if>
            </#if>
        </#list>
        where id =${r'#{id}'}
    </update>
    <!--int countAll();-->
    <select id="countAll" parameterType="${classFullName}" resultType="java.lang.Integer" >
        select count(*) from ${tableName}
    </select>
    <!--TbAddress selectByPrimaryKey(Long id);-->
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
        <include refid="${className}_selectall"/>
        where id = ${r'#{id}'}
    </select>
    <!--List<${className}> selectAll();-->
    <select id="selectAll" resultMap="BaseResultMap" >
        <include refid="${className}_selectall"/>
    </select>
    <resultMap id="BaseResultMap" type="${classFullName}" >
<#list attrs as attr>
    <#if attr.name=="id" >
        <id column="${attr.columnName}" property="${attr.name}"/>
    <#else >
        <result column="${attr.columnName}" property="${attr.name}"/>
    </#if>
</#list>
    </resultMap>

    <!--List<TbBrand> selectBySelective(TbBrand tbBrand);-->
    <select id="selectBySelective" resultMap="BaseResultMap" parameterType="${classFullName}">
        <include refid="${className}_selectall"/>
        <where>
        <#list attrs as attr>
            <#if attr.name!="id" >
                <if test="${attr.name}!=null and ${attr.name}!=''">
                    AND ${attr.columnName} =${"#{"+attr.name+"}"}
                </if>
            </#if>
        </#list>
        </where>
    </select>
</mapper>